package xyz.labmem.app.task

import xyz.labmem.app.unit.ProxyListUnit
import xyz.labmem.lipx.core.Status.FAILED
import xyz.labmem.lipx.core.Status.IDLE
import xyz.labmem.lipx.core.client.core.LabSSHPenetrationClient
import xyz.labmem.lipx.core.context.AppContext
import java.util.*

/**
 * @author       : ltty
 * @description  :
 * @createDate   : 2025/4/29
 */
object ClientAutoRunTask {

    /**
     * 启动定时器
     */
    fun start() {
        Timer().schedule(object : TimerTask() {
            override fun run() {
                try {
                    AppContext.Client.allList.forEach { (_, t) ->
                        if (t.autoRun && (t.status == IDLE || t.status == FAILED)) {
                            LabSSHPenetrationClient(t) {
                                ProxyListUnit.refresh()
                            }.connect()
                        }
                    }
                } catch (_: Exception) {
                }
            }
        }, 1000, 10000)
    }

}